package fr.labri.macchiato.client.preferences;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.DragAppearance;
import com.smartgwt.client.widgets.Img;

import fr.labri.macchiato.framework.business.model.businessEntity.BusinessEntity;

/**
 * class that designs the format of the logos and defines their behaviour are displayed in order to
 * drop them to the 'favorite providers' container
 * 
 * @author Michelle AVOMO
 * 
 */
public class BusinessEntityLogo extends Img {

	private String name;
	private BusinessEntity businessEntity;

	/**
	 * Default constructor that builds the logo and set them as elements that can be drag-dropped
	 */
	public BusinessEntityLogo() {

		this.setWidth(50);
		this.setHeight(50);
		this.setLayoutAlign(Alignment.CENTER);
		this.setCanDragReposition(true);
		this.setCanDrop(true);
		this.setDragAppearance(DragAppearance.TARGET); // changed to tracker
		this.setAppImgDir("/icon");
	}


	/**
	 * Creates a draggable logo for the given BusinessEntity 
	 * @param businessEntity The {@link BusinessEntity} associated to this logo
	 */
	public BusinessEntityLogo(BusinessEntity businessEntity) {
		this();
		setBusinessEntity(businessEntity);
		setName(businessEntity.getLegalName().replace(" ", "_"));
		setSrc(businessEntity.getSrcLogo());
		setAltText(businessEntity.getLegalName());
		setTooltip(businessEntity.getLegalName());
	}

	/********************************************** GETTERS AND SETTERS ************************************************************/

	/**
	 * @return the name of the object. Used here to identify the object in the
	 *         program
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	@Override
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the {@link BusinessEntity} associated with the logo
	 */
	public BusinessEntity getBusinessEntity() {
		return businessEntity;
	}
	
	/**
	 * @param businessEntity the {@link BusinessEntity} to link to the logo
	 */
	public void setBusinessEntity(BusinessEntity businessEntity) {
		this.businessEntity = businessEntity;
	}
	
}
